package com.zeratul.web.config;

import com.zeratul.common.core.annotation.ExcludeScan;
import com.zeratul.common.core.factory.YmlPropertySourceFactory;
import com.zeratul.common.core.stype.ServerType;
import com.zeratul.common.core.stype.ServerTypeHandler;
import com.zeratul.common.core.utils.spring.RegisterMethod;
import com.zeratul.web.utils.ServletUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;

/**
 * 服务类型配置类
 */
@ExcludeScan
@AutoConfiguration
@Slf4j
@PropertySource(value = "classpath:common-web.yml", factory = YmlPropertySourceFactory.class)
public class ServerAutoConfiguration {

    /**
     * 单体服务
     * @return
     */
    @Bean
    @ConditionalOnMissingBean(ServerTypeHandler.class)
    public ServerTypeHandler monoLithicHandler() {
        log.debug("【服务类型】当前服务类型：{}", ServerType.MONOLITHIC.getName());
        return () -> ServerType.MONOLITHIC;
    }

    /**
     * 定义请求参数获取的解析方法
     * @return
     */
    @Bean
    public RegisterMethod requestRegisterMethod() {
        RegisterMethod registerMethod = new RegisterMethod();
        registerMethod.setRegisterMethodObjCls(ServletUtils.class);
        registerMethod.setMethodName("getParameter");
        registerMethod.setExecMethodName("param");
        registerMethod.addParamClass(String.class);
        return registerMethod;
    }
}
